//package com.itisyue.fun.config;
//
//import cn.hippo4j.core.executor.DynamicThreadPool;
//import cn.hippo4j.core.executor.support.ResizableCapacityLinkedBlockIngQueue;
//import cn.hippo4j.core.executor.support.ThreadPoolBuilder;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.scheduling.annotation.EnableAsync;
//import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
//
//import java.util.concurrent.ThreadPoolExecutor;
//import java.util.concurrent.TimeUnit;
//
//@Configuration
////@EnableAsync
//public class ThreadPoolTaskConfig {
//    Logger log = LoggerFactory.getLogger(ThreadPoolTaskConfig.class);
//
//    private static int cpu = Runtime.getRuntime().availableProcessors();
//    private static final int corePoolSize = cpu * 40;
//    private static final int maxPoolSize = cpu * 400;
//    private static final int keepAliveTime = 10;
//    private static final int queueCapacity = 1000;
//    private static final String threadNameprefix = "Async-Service-";
//
////    @Bean("taskExecutor2")
////    @DynamicThreadPool
////    public ThreadPoolTaskExecutor taskExecutor(){
////        log.info("初始化线程池配置... 服务器cpu数="+cpu+", corePoolSize="+corePoolSize+", maxPoolSize="+maxPoolSize+", queueCapacity="+queueCapacity);
////        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
////        executor.setCorePoolSize(corePoolSize);
////        executor.setMaxPoolSize(maxPoolSize);
////        executor.setQueueCapacity(queueCapacity);
////        executor.setKeepAliveSeconds(keepAliveTime);
////        executor.setThreadNamePrefix(threadNameprefix);
////        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
////
////        executor.initialize();
////        return executor;
////
////    }
//
//    @Bean("taskExecutor")
////    @DynamicThreadPool
//    public ThreadPoolExecutor dynamicThreadPoolExecutor() {
//        log.info("初始化线程池配置... 服务器cpu数="+cpu+", corePoolSize="+corePoolSize+", maxPoolSize="+maxPoolSize+", queueCapacity="+queueCapacity);
//        String threadPoolId = "message-consumer";
//        ThreadPoolExecutor dynamicExecutor = ThreadPoolBuilder.builder()
//                .threadFactory(threadPoolId)
//                .threadPoolId(threadPoolId)
//                .corePoolSize(corePoolSize)
//                .maxPoolNum(maxPoolSize)
//                .workQueue(new ResizableCapacityLinkedBlockIngQueue(queueCapacity))
//                .rejected(new ThreadPoolExecutor.AbortPolicy())
//                .keepAliveTime(6000, TimeUnit.MILLISECONDS)
//                .dynamicPool()
//                .build();
//        return dynamicExecutor;
//    }
//}
